package com.wkx.service.impl;/**
 * @className: MenuServiceImpl
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/8
 **/

import com.wkx.mapper.MenuMapper;
import com.wkx.pojo.Menu;
import com.wkx.pojo.Roles;
import com.wkx.service.MenuService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName : MenuServiceImpl  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/8  11:42
 */
//增删改事务处理
//@Transactional(propagation = Propagation.REQUIRED)
//查询 （只读）
//@Transactional(readOnly = true)
@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    MenuMapper menuMapper;
    @Transactional(readOnly = true)
    @Override
    public List<Menu> getMenuList(Integer parent_id, List<Roles> roles) {
        return menuMapper.selectMenus(parent_id, roles);
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public List<Menu> getRoleMenuListByRid(Integer rid) {
        return menuMapper.selectMenusByRid(rid);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void updateRoleMenus(Integer[] roles, Integer rid){
        int i = menuMapper.deleteMenusByRid(rid);
        if(roles.length!=0&&roles!=null) {
            for (Integer menu : roles) {
                menuMapper.insertMenus(menu, rid);
            }

        }
    }


    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addMenu(Menu menu) {
        menuMapper.insert(menu);
    }

    @Override
    public Menu getMenuByMid(Integer mid) {
        return menuMapper.selectByPrimaryKey(mid);
    }

    @Override
    public void updateMenu(Menu menu) {
        menuMapper.updateByPrimaryKey(menu);
    }


}
